import { useEffect } from "react"
import { getClientWS } from "../../run/getClientWS"
import { WsNotifyType } from "../../consts/wsNotifyType"

export const useWatchWsNotify = (type, onNotify) => {
    useEffect(() => {
        const notify = (message) => {
            const { type: messageType, data } = message
            if (messageType === type) {
                WsNotifyType[type].notify({ data, onNotify })
            }
        }

        getClientWS({ notify })
    }, [])
}